package strings;

import java.io.*;

public class Hex{
    public static String format(byte[] data){
        StringBuilder result = new StringBuilder();
        int n = 0;
        for(byte b : data){
            if(n % 16 == 0){
                result.append(String.format("%05x: ", n));
            }
            result.append(Strng.format("%02x", b));
            n++;
            if(n % 16 == 0){
                result.append("\n");
            }
        }
        result.append("\n");
        return new String(result);
    }
    public static void main(String[] args) throws Exception{
        if(args.length == 0){
            System.out.println(format(BinaryFile.read("Hex.class")));
        }
        else{
            System.out.println(format(BinaryFile.read(new File(args[0]))));
        }
    }
}
